<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
#ta {
	font-size: 18px;
	margin-top: 80px;
	margin-left: 300px;
}

.but {
	width: 50px;
	margin: auto;
	margin-top: 35px;
}

tr input {
	margin-top: 20px;
}

tr select {
	width: 203px;
	height: 35px;
}

tr td span {
	color: red;
}
</style>
<script type="text/javascript">
	var tr = 0;
	function bl() {
		//var reg = [\u4e00-\u9fa5];

		var id = $("#communityId").val();
		var tower1 = $("#tower1").val();
		var tower2 = $("#tower2").val();
		var tower = tower1 + "栋" + tower2;
		var INhouse = $("#INhouse").val();
		var houseIN = INhouse + "号楼";
		$.ajaxSettings.async = false;
		$.ajax({
			type : "post",
			url : "/property/owner/getTow",
			data : {
				"id" : id,
				"tower" : tower,
				"houseIN" : houseIN
			},
			dataType : "json",
			success : function(data) {
				if (data > 0) {
					$("#DivINhouse").html("此房屋楼栋，已有人入驻住");
					tr = 1;
				} else {
					tr = 0;
				}

			},
			error : function() {
				alert("加载失败！");
				return false;
			}
		})
		$.ajaxSettings.async = true;
	}
	$(function() {
		tr = 0;
		$("#communityId").blur(checkcommunityId);
		$("#name").blur(checkname);
		$("#phone").blur(checkphone);
		$("#tower2").blur(checktower);
		$("#INhouse").blur(checkINhouse);
		$("#btn").click(function() {
			var flag = true;

			if (!checkcommunityId()) {
				flag = false;
			}
			if (!checkname()) {
				flag = false;
			}
			if (!checkphone()) {
				flag = false;
			}
			if (!checktower()) {
				flag = false;
			}
			if (!checkINhouse()) {
				flag = false;
			}
			bl();
			if (tr == 1) {
				flag = false;
			} else {
				flsg = true;
			}

			if (flag == true) {

				$("#sub").submit();
			}
		});
	})
	function checkcommunityId() {
		$("#DivId").html("");
		if ($("#communityId").val() == 0) {
			$("#DivId").html("小区名字不能为空");
			return false;
		}
		return true;
	}

	function checkname() {
		$("#DivName").html("");
		if ($("#name").val() == "") {
			$("#DivName").html("业主名字不能为空");
			return false;
		}
		return true;
	}
	function checkphone() {
		var reg= /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;

		$("#DivPhone").html("");
		if ($("#phone").val() == "") {
			$("#DivPhone").html("联系电话不能为空");
			return false;
		}
		if(!reg.test($("#phone").val())){
			$("#DivPhone").html("格式不正确");
			return false;
		}
		return true;
	}
	function checktower() {
		$("#DivTower").html("");
		if ($("#tower1").val() == "" && $("#tower2").val() == "") {
			$("#DivTower").html("所在楼栋不能为空");
			return false;
		}
		var re = /^[0-9]{3}$/;
		var tower2 = $("#tower2").val();
		var res = /^[1-9]{1}$/;
		var tower1 = $("#tower1").val();

		if (tower1 > 10) {
			$("#DivTower").html("还未开发，请重新输入1~9栋");
			return false;

		}
		if (!re.test(tower2) || !res.test(tower1)) {
			$("#DivTower").html("输入格式错误！");
			return false;
		}

		return true;
	}
	function checkINhouse() {
		$("#DivINhouse").html("");
		var resa = /^[1-9]{1,2}$/;
		var INhouse = $("#INhouse").val();
		if ($("#INhouse").val() == "") {
			$("#DivINhouse").html("所在房屋不能为空");
			return false;
		}
		if (INhouse > 20) {
			$("#DivINhouse").html("没有此号楼，请重新输入1~20号楼");
			return false;
		}
		if (!resa.test(INhouse)) {
			$("#DivINhouse").html("输入格式错误！");
			return false;
		}

		return true;
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div
		style="width: 1050px; height: 570px; background-color: #FFF; margin: 20px;">
		<h4
			style="background-color: #9FB2C2; padding-left: 10px; color: #516D8A; line-height: 40px;">
			<img alt="" src="${initParam.url}/statics/images/title.jpg">房屋添加
		</h4>
		<form action="${initParam.url }/owner/doaddOwner" method="post"
			id="sub">
			<input type="hidden" id="id" value="${users.id}" name="id" />
			<table id="ta">

				<tr>
					<td>小区名字：
					<td>
					<td><select name="communityId" id="communityId">
							<option value="0">请选择</option>
							<c:forEach var="li" items="${list}">
								<option value="${ li.id}">${li.communityName }</option>
							</c:forEach>
					</select>
					<td>&nbsp;&nbsp;
					<td><span id="DivId"></span>
					<td>
				</tr>
				<tr>
					<td>业主姓名：
					<td>
					<td><input type="text" name="name" id="name">
					<td>&nbsp;&nbsp;
					<td><span id="DivName"></span>
					<td>
				</tr>
				<tr>
					<td>联系电话：
					<td>
					<td><input type="text" name="phone" id="phone">
					<td>&nbsp;&nbsp;
					<td><span id="DivPhone"></span>
					<td>
				</tr>
				<tr>
					<td>所在楼栋：
					<td>
					<td><input style="width: 65px;" type="text" name="tower1"
						id="tower1">栋&nbsp;<input style="width: 108px;"
						type="text" name="tower2" id="tower2">&nbsp;&nbsp;<span
						style="color: gray; font-size: 14px;">如：2栋 206</span>
					<td>&nbsp;&nbsp;
					<td><span id="DivTower"></span>
					<td>
				</tr>
				<tr>
					<td>所在房屋：
					<td>
					<td><input type="text" name="INhouse" style="width: 160px;"
						id="INhouse" onblur="bl();">号楼&nbsp;&nbsp;<span
						style="color: gray; font-size: 14px;">如：2号楼</span>
					<td>&nbsp;&nbsp;
					<td><span id="DivINhouse"></span>
					<td>
				</tr>

			</table>
			<div class="but">
				<input type="button" value="添加" class="btn btn-primary btn-lg"
					id="btn">
			</div>
		</form>
	</div>
</body>
</html>